using System.Collections.Generic;
using UnityEngine;

public class InfoFromPoint : MonoBehaviour
{
	public static InfoFromPoint instance;

	public GameObject goWithCollider;

	public GameObject ObjectForMovingPoint;

	private Transform[] allPoint;

	public List<PointForBonuse> listPointSpawn = new List<PointForBonuse>();

	public virtual void Awake()
	{
		instance = this;
	}

	public virtual void SavePoint()
	{
		listPointSpawn.Clear();
		allPoint = GetComponentsInChildren<Transform>();
		Transform[] array = allPoint;
		foreach (Transform transform in array)
		{
			if (transform.tag.Equals("Respawn"))
			{
				PointForBonuse item = default(PointForBonuse);
				item.pos = transform.transform.position;
				BonuseRespawnInfo component = transform.GetComponent<BonuseRespawnInfo>();
				item.bonuse = component.bonuse;
				item.options = component.options;
				item.timeForRespawnBonuse = component.timeForRespawnBonuse;
				item.listBonuse = new List<SpawnBonuse>();
				item.listBonuse.AddRange(component.listBonuse.ToArray());
				listPointSpawn.Add(item);
			}
		}
	}

	public virtual void ShowPoint()
	{
		foreach (PointForBonuse item in listPointSpawn)
		{
			GameObject gameObject = Object.Instantiate(ObjectForMovingPoint);
			gameObject.SetActive(true);
			gameObject.transform.position = item.pos;
			gameObject.transform.parent = base.transform;
			BonuseRespawnInfo component = gameObject.GetComponent<BonuseRespawnInfo>();
			component.options = item.options;
			component.timeForRespawnBonuse = item.timeForRespawnBonuse;
			component.listBonuse = item.listBonuse;
			component.bonuse = item.bonuse;
			foreach (SpawnBonuse item2 in component.listBonuse)
			{
				gameObject.gameObject.name += item2.spawnType;
			}
		}
	}

	public void DeletePoint()
	{
		allPoint = GetComponentsInChildren<Transform>();
		Transform[] array = allPoint;
		foreach (Transform transform in array)
		{
			if (transform.tag.Equals("Respawn"))
			{
				Object.DestroyImmediate(transform.gameObject);
			}
		}
	}

	public void PutAllPoint()
	{
		Ray ray = default(Ray);
		RaycastHit hitInfo = default(RaycastHit);
		for (int i = 0; i < listPointSpawn.Count; i++)
		{
			PointForBonuse value = listPointSpawn[i];
			ray.origin = value.pos + Vector3.up;
			ray.direction = Vector3.down;
			if (Physics.Raycast(ray, out hitInfo, 10000f))
			{
				value.pos = hitInfo.point;
				listPointSpawn[i] = value;
			}
		}
	}
}
